package com.example.springboot.base;

import lombok.Data;

/**
 * 统一API响应结果封装
 */

@Data
public class Result {

    private int code;

    private String message = "success";

    private Object data;

    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

    public static Result success(){
        return setResult(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),"");
    }

    public static Result success(Object data){
        return  setResult(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),data);
    }
    public static Result success(String message){
        return  setResult(ResultCode.SUCCESS.getCode(),message,"");
    }
    public static Result success(String message,Object data){
        return  setResult(ResultCode.SUCCESS.getCode(),message,data);
    }
    public static Result success(int code,String message,Object data){
        return  setResult(code,message,data);
    }

    public static Result error(String message){
        return  setResult(ResultCode.FAIL.getCode(),message,"");
    }
    public static Result error(int code,String message){
        return  setResult(code,message,"");
    }
    public static Result error(String message,String data){
        return  setResult(ResultCode.FAIL.getCode(),message,data);
    }
    public static Result setResult(int code,String message,Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;

    }


}